using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;

namespace DocumentManagement
{
  /// <summary>
  /// Tdoctypes Data Object Class
  /// </summary>
  public partial class DOTdoctypes
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Tdoctypes doctype
		/// </summary>
		public const string Rowdoctype = "doctype";

		/// <summary>
		/// The Table Column for the Tdoctypes mandatory
		/// </summary>
		public const string Rowmandatory = "mandatory";

		/// <summary>
		/// The Table Column for the Tdoctypes useqc
		/// </summary>
		public const string Rowuseqc = "useqc";

		/// <summary>
		/// The Table Column for the Tdoctypes initreq
		/// </summary>
		public const string Rowinitreq = "initreq";

		/// <summary>
		/// The Table Column for the Tdoctypes dispseq
		/// </summary>
		public const string Rowdispseq = "dispseq";

		/// <summary>
		/// The Table Column for the Tdoctypes tooltip
		/// </summary>
		public const string Rowtooltip = "tooltip";

		/// <summary>
		/// The Table Column for the Tdoctypes barcode
		/// </summary>
		public const string Rowbarcode = "barcode";

		/// <summary>
		/// The Table Column for the Tdoctypes istd
		/// </summary>
		public const string Rowistd = "istd";

		/// <summary>
		/// The Table Column for the Tdoctypes ismb
		/// </summary>
		public const string Rowismb = "ismb";

		/// <summary>
		/// The Table Column for the Tdoctypes isrelease
		/// </summary>
		public const string Rowisrelease = "isrelease";

		/// <summary>
		/// The Table Column for the Tdoctypes containername
		/// </summary>
		public const string Rowcontainername = "containername";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTdoctypes_Create";
private const string m_StoredProcedureConstDelete = "spTdoctypes_Delete";
private const string m_StoredProcedureConstRetrieve = "spTdoctypes_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTdoctypes_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTdoctypes_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_doctype;
		private bool m_mandatory;
		private bool m_useqc;
		private int m_initreq;
		private int m_dispseq;
		private string m_tooltip;
		private string m_barcode;
		private bool m_istd;
		private bool m_ismb;
		private bool m_isrelease;
		private string m_containername;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTdoctypes> m_Tdoctypess = new List<DOTdoctypes>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTdoctypes() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// doctype
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes doctype
		/// </remarks>
		public string doctype
		{
			get { return (this.m_doctype); }
			set { this.m_doctype = value; }
		}

		/// <summary>
		/// mandatory
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes mandatory
		/// </remarks>
		public bool mandatory
		{
			get { return (this.m_mandatory); }
			set { this.m_mandatory = value; }
		}

		/// <summary>
		/// useqc
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes useqc
		/// </remarks>
		public bool useqc
		{
			get { return (this.m_useqc); }
			set { this.m_useqc = value; }
		}

		/// <summary>
		/// initreq
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes initreq
		/// </remarks>
		public int initreq
		{
			get { return (this.m_initreq); }
			set { this.m_initreq = value; }
		}

		/// <summary>
		/// dispseq
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes dispseq
		/// </remarks>
		public int dispseq
		{
			get { return (this.m_dispseq); }
			set { this.m_dispseq = value; }
		}

		/// <summary>
		/// tooltip
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes tooltip
		/// </remarks>
		public string tooltip
		{
			get { return (this.m_tooltip); }
			set { this.m_tooltip = value; }
		}

		/// <summary>
		/// barcode
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes barcode
		/// </remarks>
		public string barcode
		{
			get { return (this.m_barcode); }
			set { this.m_barcode = value; }
		}

		/// <summary>
		/// istd
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes istd
		/// </remarks>
		public bool istd
		{
			get { return (this.m_istd); }
			set { this.m_istd = value; }
		}

		/// <summary>
		/// ismb
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes ismb
		/// </remarks>
		public bool ismb
		{
			get { return (this.m_ismb); }
			set { this.m_ismb = value; }
		}

		/// <summary>
		/// isrelease
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes isrelease
		/// </remarks>
		public bool isrelease
		{
			get { return (this.m_isrelease); }
			set { this.m_isrelease = value; }
		}

		/// <summary>
		/// containername
		/// </summary>
		/// <remarks>
		/// This property contains the Tdoctypes containername
		/// </remarks>
		public string containername
		{
			get { return (this.m_containername); }
			set { this.m_containername = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTdoctypes> Tdoctypess
	{
	  get { return m_Tdoctypess; }
	  set { m_Tdoctypess = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + Rowdoctype + "=" + this.doctype);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[Rowdoctype].ToString() != "")
			this.doctype = dr[Rowdoctype].ToString();

		if (dr[Rowmandatory].ToString() != "")
			this.mandatory = bool.Parse(dr[Rowmandatory].ToString());

		if (dr[Rowuseqc].ToString() != "")
			this.useqc = bool.Parse(dr[Rowuseqc].ToString());

		if (dr[Rowinitreq].ToString() != "")
			this.initreq = int.Parse(dr[Rowinitreq].ToString());

		if (dr[Rowdispseq].ToString() != "")
			this.dispseq = int.Parse(dr[Rowdispseq].ToString());

		if (dr[Rowtooltip].ToString() != "")
			this.tooltip = dr[Rowtooltip].ToString();

		if (dr[Rowbarcode].ToString() != "")
			this.barcode = dr[Rowbarcode].ToString();

		if (dr[Rowistd].ToString() != "")
			this.istd = bool.Parse(dr[Rowistd].ToString());

		if (dr[Rowismb].ToString() != "")
			this.ismb = bool.Parse(dr[Rowismb].ToString());

		if (dr[Rowisrelease].ToString() != "")
			this.isrelease = bool.Parse(dr[Rowisrelease].ToString());

		if (dr[Rowcontainername].ToString() != "")
			this.containername = dr[Rowcontainername].ToString();
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTdoctypes Tdoctypes = new DOTdoctypes();
			
					if (dr[Rowdoctype].ToString() != "")
			Tdoctypes.doctype = dr[Rowdoctype].ToString();

		if (dr[Rowmandatory].ToString() != "")
			Tdoctypes.mandatory = bool.Parse(dr[Rowmandatory].ToString());

		if (dr[Rowuseqc].ToString() != "")
			Tdoctypes.useqc = bool.Parse(dr[Rowuseqc].ToString());

		if (dr[Rowinitreq].ToString() != "")
			Tdoctypes.initreq = int.Parse(dr[Rowinitreq].ToString());

		if (dr[Rowdispseq].ToString() != "")
			Tdoctypes.dispseq = int.Parse(dr[Rowdispseq].ToString());

		if (dr[Rowtooltip].ToString() != "")
			Tdoctypes.tooltip = dr[Rowtooltip].ToString();

		if (dr[Rowbarcode].ToString() != "")
			Tdoctypes.barcode = dr[Rowbarcode].ToString();

		if (dr[Rowistd].ToString() != "")
			Tdoctypes.istd = bool.Parse(dr[Rowistd].ToString());

		if (dr[Rowismb].ToString() != "")
			Tdoctypes.ismb = bool.Parse(dr[Rowismb].ToString());

		if (dr[Rowisrelease].ToString() != "")
			Tdoctypes.isrelease = bool.Parse(dr[Rowisrelease].ToString());

		if (dr[Rowcontainername].ToString() != "")
			Tdoctypes.containername = dr[Rowcontainername].ToString();

            this.Tdoctypess.Add(Tdoctypes);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
